package com.takeshequ;

import java.util.HashMap;
import java.util.Map;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.FinalBitmap;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.google.gson.Gson;
import com.takeshequ.chat.ExpressionUtil;
import com.utils.SharedPreferencesUtils;

@SuppressLint("UseSparseArrays")
public class BasicActivity extends FinalActivity {
	protected SharedPreferencesUtils sharedPreferencesUtils;
	protected Gson gson;

	protected FinalBitmap finalBitmap;
	protected Map<Integer, View> viewMap = new HashMap<Integer, View>();

	@Override
	public void startActivity(Intent intent) {
		super.startActivity(intent);
		super.overridePendingTransition(R.anim.push_right_in,
				R.anim.push_left_out);

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		gson = new Gson();
		finalBitmap = FinalBitmap.create(this);
	}

	@Override
	protected void onResume() {

		super.onResume();
		sharedPreferencesUtils = SharedPreferencesUtils
				.getInstance(BasicActivity.this);
		ImageButton button = (ImageButton) findViewById(R.id.top_back);
		if (button instanceof ImageButton) {
			button.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					BasicActivity.this.finish();
					overridePendingTransition(R.anim.push_left_in,
							R.anim.push_right_out);
				}
			});
		}
	}

	protected SpannableString getSpannableString(String content) {
		if (content == null)
			content = "";
		return ExpressionUtil.getExpressionString(this, content);
	}

	protected void displayImage(ImageView imageView, String uri) {
		if (imageView instanceof ImageView)
			finalBitmap.display(imageView, uri);

	}

	protected void showGender(ImageView imageView, String gender) {
		if (gender instanceof String) {
			if (gender.equals("m")) {
				imageView.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.friends_item_male));
			} else {
				imageView.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.friends_item_female));
			}
		}

	}
}
